<?php
/** Copyright 2014 TinPhp Systems, Inc.
 * @author zhangxilian 2013-8-15
 */
if (!defined('IN_TINPHP')) {
    exit('Access Denied');
}

require_once('adminApp.php');

class LoginController extends AdminAppController {
	
	public function __construct() {
		$this->chkLogin = false;
        parent::__construct();
	}
 	/** 登录 */
 	public function actionDefault(){ 		
 		T::$tplFile='admin/index/login';
 		if($_POST['btnlogin']){
 			
 			$tourl = $_REQUEST['tourl'];
 			if(trim($_SESSION["validCode"])!=trim($_POST['code'])){
 				return $this->sysMessage('验证码错误。', "", 3);
 			}
 			$cond = 'state=1 and username="'.$_POST['username'].'" and password="'.md5($_POST['password']).'"';
 			try{
 			$uItem = $this->Logic('AccountLogic')->getAccountItem('*', $cond);
 			}catch(Exception $e){
 				//echo $e->getMessage();
 			}
 			if($uItem){
				$uItem['LOGIN_TIME'] = date("Y-m-d H:i:s", time());
 				Auth::setAdminInfo($uItem);
 				$this->saveDbLogs('sys_admin','管理员['.$_POST['username'].']登录成功');
 				if(!$tourl)
 					$tourl = 'admin.php';
 				header("Location:".$tourl);
 				//return $this->sysMessage("登录成功",array("进入后台"=>$tourl),1);
 			}else{
 				$this->saveDbLogs('sys_admin','管理员['.$_POST['username'].']登录,用户名或密码错误');
 				return $this->sysMessage('用户名或密码错误。', "", 3);
 			}
 		}
 		
 	}
 	/** 退出登录 */
 	public function actionLogout(){
 		T::$tplFile='public/empty';
 		Auth::loginOutAdmin();
 		return $this->sysMessage("已经安全退出",array("返回登录"=>"admin.php?ctl=login","返回首页"=>"index.php"), 3);
 	}
 	
}//End CLass
?>
